package com.yanqu.road.dao.impl.activity.hsisland;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.hsisland.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

public class HsIslandConfigDaoImpl extends TempDao {

    /**
     * 船配置表
     */
    public Map<Integer, HsIslandBoatConfig> getBoatConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_boat` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandBoatConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandBoatConfig config = new HsIslandBoatConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setAppearance(rs.getInt("appearance"));
                config.setExp(rs.getInt("exp"));
                config.setPowerIncrease(rs.getInt("powerIncrease"));
                config.setName(rs.getString("name"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 岛配置表
     */
    public Map<Integer, HsIslandIslandConfig> getIslandConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_island` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandIslandConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandIslandConfig config = new HsIslandIslandConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setLatticeParam(rs.getString("latticeParam"));
                config.setLatticeWeight(rs.getString("latticeWeight"));
                config.setBigPveNum(rs.getInt("bigPveNum"));
                config.setAllEventNum(rs.getInt("allEventNum"));
                config.setMapType(rs.getInt("mapType"));
                config.setMapParam(rs.getString("mapParam"));
                config.setPngParam(rs.getString("pngParam"));
                config.setWeight(rs.getInt("weight"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 事件配置表
     */
    public Map<Integer, HsIslandEventConfig> getEventConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_event` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandEventConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandEventConfig config = new HsIslandEventConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setLatticeParam(rs.getString("latticeParam"));
                config.setCanTransit(rs.getInt("canTransit"));
                config.setIsHighlight(rs.getInt("isHighlight"));
                config.setIsNotice(rs.getInt("isNotice"));
                config.setPersonNoticeText(rs.getString("personNoticeText"));
                config.setGuildNoticeText(rs.getString("guildNoticeText"));
                config.setCanWorkBuff(rs.getString("canWorkBuff"));
                config.setEventDesc(rs.getString("eventDesc"));
                config.setEventExplain(rs.getString("eventExplain"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * PVE配置表
     */
    public Map<Integer, HsIslandPveConfig> getPveConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_pve` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandPveConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandPveConfig config = new HsIslandPveConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setType(rs.getInt("type"));
                config.setAppearanceId(rs.getString("appearanceId"));
                config.setName(rs.getString("name"));
                config.setDesc(rs.getString("desc"));
                config.setTab(rs.getInt("tab"));
                config.setTitle(rs.getString("title"));
                config.setTalkText(rs.getString("talkText"));
                config.setHp(rs.getString("hp"));
                config.setQuality(rs.getInt("quality"));
                config.setReward(rs.getString("reward"));
                config.setScore(rs.getInt("score"));
                config.setCanInviteNum(rs.getInt("canInviteNum"));
                config.setWeight(rs.getInt("weight"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * PVP结算配置MAP
     */
    public Map<Integer, HsIslandDuelConfig> getDuleConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_duel` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandDuelConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandDuelConfig config = new HsIslandDuelConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setVictoryNum(rs.getString("victoryNum"));
                config.setReward(rs.getString("reward"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 宝箱配置MAP
     */
    public Map<Integer, HsIslandBoxConfig> getBoxConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_box` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandBoxConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandBoxConfig config = new HsIslandBoxConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setReward(rs.getString("reward"));
                config.setNum(rs.getInt("num"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 2选1配置MAP
     */
    public Map<Integer, HsIslandChooseConfig> getChooseConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_choose` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandChooseConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandChooseConfig config = new HsIslandChooseConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setTitle(rs.getString("title"));
                config.setDesc(rs.getString("desc"));
                config.setChooseTitle(rs.getString("chooseTitle"));
                config.setIcon(rs.getString("icon"));
                config.setChooseText(rs.getString("chooseText"));
                config.setTrueReward(rs.getString("trueReward"));
                config.setErrorReward(rs.getString("errorReward"));
                config.setType(rs.getString("type"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * BUFF配置MAP
     */
    public Map<Integer, HsIslandBuffConfig> getBuffConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_buff` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandBuffConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandBuffConfig config = new HsIslandBuffConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setType(rs.getInt("type"));
                config.setName(rs.getString("name"));
                config.setDesc(rs.getString("desc"));
                config.setParam(rs.getString("param"));
                config.setTimes(rs.getInt("times"));
                config.setWeight(rs.getInt("weight"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 遗迹藏宝配置MAP
     */
    public Map<Integer, HsIslandRelicConfig> getRelicConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_relic` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandRelicConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandRelicConfig config = new HsIslandRelicConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setReward(rs.getString("reward"));
                config.setWeight(rs.getInt("weight"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * BOSS奖励配置MAP
     */
    public Map<Integer, HsIslandBossRewardConfig> getBossRewardConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_bossaward` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandBossRewardConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandBossRewardConfig config = new HsIslandBossRewardConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setRank(rs.getString("rank"));
                config.setReward(rs.getString("reward"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

    /**
     * 圣柱奖励配置表
     */
    public Map<Integer, HsIslandGiftConfig> getGiftConfigMap(int activityId) {
        String geSql = "select * from `t_s_activity_hsisland_gift` where `activityId` = ? ORDER BY `id` ASC";
        Map<Integer, HsIslandGiftConfig> map = new LinkedHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(geSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                HsIslandGiftConfig config = new HsIslandGiftConfig();
                config.setActivityId(rs.getInt("activityId"));
                config.setId(rs.getInt("id"));
                config.setName(rs.getString("name"));
                config.setAppearanceId(rs.getString("appearanceId"));
                config.setReward(rs.getString("reward"));
                config.setWeight(rs.getInt("weight"));
                config.setScore(rs.getInt("score"));
                map.put(config.getId(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }
}
